/**
 * 
 */
package com.wubo.sec.acl;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import com.wubo.sec.acl.core.AclManager;
import com.wubo.sec.bean.UserGroupRelate;
import com.wubo.sec.model.Group;
import com.wubo.sec.model.User;
import com.wubo.sec.service.IGroupService;
import com.wubo.sec.service.IUserService;

/**
 * @author WuBo
 * @CreateDate 2012-4-24
 */
@Component
public class UserGroupAcl extends EntityRelateAcl {
	@Resource
	private IUserService userService;
	@Resource
	private IGroupService groupService;

	public int getAcl(Object obj) {
		UserGroupRelate ugr = (UserGroupRelate) obj;
		User user = userService.get(ugr.getUsername());
		int userAcl = new UserAcl(user).getAcl();
		if(! AclManager.getInstance().hasActions(userAcl, "ACL_DEL")){
			return 0;
		}
		
		Group group = groupService.get(ugr.getGroupCode());
		int groupAcl = new GroupAcl(group).getAcl();
		if(! AclManager.getInstance().hasActions(groupAcl, "ACL_DEL")){
			return 0;
		}
		return 0;
	}
}
